def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def closest_prime(num):
    offset = 0
    while True:
        if is_prime(num - offset):
            return num - offset
        elif is_prime(num + offset):
            return num + offset
        offset += 1

words_to_numbers = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

def words_to_num(words):
    try:
        return int(''.join(str(words_to_numbers[word]) for word in words.split()))
    except KeyError:
        return "Wrong input"

input_words = input("")
number = words_to_num(input_words)

if isinstance(number, int) and 100 <= number <= 999:
    print(closest_prime(number))
else:
    print("Wrong input")
